﻿using DavidJalbert.TinyCarControllerAdvance;
using NodeCanvas.Framework;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    public class CarBaseNode : ActionTask
    {
        protected CarEntity _carEntity;

        protected CarData _data;

        protected VehicleAI _vehicleAI;

        protected TCCAPlayer _carController;
        
        protected override string OnInit()
        {
            _carEntity = ownerSystemBlackboard.GetVariable<CarEntity>("CarEntity").value;
            _data = _carEntity.data;
            _vehicleAI = _carEntity.vehicleAI;
            _carController = _carEntity.carController;
            return null;
        }

        protected override void PreOnExecute()
        {
            if (_carEntity == null)
            {
                _carEntity = ownerSystemBlackboard.GetVariable<CarEntity>("CarEntity").value;
                _data = _carEntity.data;
                _vehicleAI = _carEntity.vehicleAI;
                _carController = _carEntity.carController;
            }
        }

        protected override void OnStop()
        {
            _carEntity = null;
        }
    }
}